//
//  MDViewController.m
//  MenuDesigner
//
//  Created by viki on 7/4/14.
//  Copyright (c) 2014 viki. All rights reserved.
//

#import "MDViewController.h"
#import "UIColor+Expanded.h"

@interface MDViewController ()

@end

static int  const MARGIN = 12;


@implementation MDViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    self.menuArray = @[@{@"x": @2, @"y": @2, @"width": @288, @"height": @140, @"color": @"#f00fff",@"inverseColor": @"#00ffff", @"label": @"first one", @"action": @"open_meeting"},
                       @{@"x": @2, @"y": @150, @"width": @140, @"height": @140, @"color": @"#000fff",@"inverseColor": @"#00ff0f", @"label": @"second one", @"action": @"open_survey"}
                       ];
    [self initUI];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initUI{

    for (int i = 0; i< self.menuArray.count; i++) {
        NSDictionary *dic = [self.menuArray objectAtIndex:i];

        CGRect frame = CGRectMake(MARGIN + [[dic valueForKey:@"x"] intValue], MARGIN+[[dic valueForKey:@"y"] intValue],[[dic valueForKey:@"width"] intValue], [[dic valueForKey:@"height"] intValue]);
        UIView *view = [[UIView alloc] initWithFrame:frame];
        view.backgroundColor = [UIColor colorWithHexString:[dic valueForKey:@"color"]];
        [self.view addSubview:view];
        
        UILabel *label = [[UILabel alloc] initWithFrame:frame];
        label.text = [dic valueForKey:@"label"];
        label.textAlignment = UITextAlignmentCenter;
        label.textColor = [UIColor colorWithHexString:[dic  valueForKey:@"inverseColor"]];
        [self.view addSubview:label];
        
        UIControl *control = [[UIControl alloc] initWithFrame:frame];
        [control addTarget:self action:NSSelectorFromString( [dic valueForKey:@"action"]) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:control];
        
        
    }
    
}
- (void)open_meeting{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"click open_meeting menu" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
}
- (void)open_survey{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"click open_survey menu" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
}
@end
